<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/file-writer-utils.js"></script>
<script>
promise_test(t => {
  const name = 'foo';
  let filesystem;
  return new Promise((resolve, reject) => {
    webkitRequestFileSystem(TEMPORARY, 1024, resolve, reject);
  }).then(fs => {
    filesystem = fs;
    return new Promise((resolve, reject) => {
      fs.root.getFile(name, {create: true}, resolve, reject);
    });
  }).then(entry => {
    return new Promise((resolve, reject) => {
      entry.createWriter(resolve, reject);
    });
  }).then(writer => {
    return new Promise((resolve, reject) => {
      writer.onwriteend = resolve;
      writer.error = reject;
      writer.write(new Blob(['hello']));
    });
  }).then(() => {
    return new Promise((resolve, reject) => {
      filesystem.root.getFile(name, {}, resolve, reject);
    });
  }).then(entry => {
    return new Promise((resolve, reject) => {
       entry.file(resolve, reject);
    });
  }).then(file => {
    const form = new FormData();
    form.append('name', file);
    return new Response(form).text();
  }).then(text => {
    assert_true(text.search('hello') >= 0, 'text should contain "hello"');
  }, 'Response.text() for a form containing a file got from FileSystem API.');
});
</script>
